﻿<?php 
$page=1;
if(isset($_REQUEST['page'])){
	$page=$_REQUEST['page'];
}
$rowpage=10;
$pagestart=($page-1)*$rowpage;
$pageend=$pagestart+$rowpage;

$link='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$_SESSION['linkdeal']=$link;
$numpage=ceil(count($list_deal)/$rowpage);

$date = date("Y-m-d");
$date = strtotime(date("Y-m-d", strtotime($date)) . "-12 months");
if(isset($_REQUEST['m_start']))
$m_start = $_REQUEST['m_start'];
else
$m_start = date("Y-m-d",$date);
if(isset($_REQUEST['m_end']))
$m_end = $_REQUEST['m_end'];
else
$m_end=date("Y-m-d");
?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url('css/jsDatePick_ltr.min.css') ?>" />
<script type="text/javascript" src="<?php echo base_url('js/jsDatePick.min.1.3.js') ?>"></script>

<script type="text/javascript">
window.onload = function(){
	new JsDatePick({
        useMode:2,
        target:"m_start",
        dateFormat:"%Y-%m-%d"
    });
	new JsDatePick({
        useMode:2,
        target:"m_end",
        dateFormat:"%Y-%m-%d"
    });
};

function getFormattedDate(year,month,day) {
	  month = month.length > 1 ? month : '0' + month;
	  day = day.length > 1 ? day : '0' + day;
	  return year + '-' + month + '-' + day;
}
function onchangetime(co){
	if(co==1){
		var d= new Date();
		document.getElementById('m_start').value=getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		document.getElementById('m_end').value=getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
	}
	if(co==-1){
		var d= new Date();
		d.setDate(d.getDate() -1);
		document.getElementById('m_end').value= getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		document.getElementById('m_start').value=getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		
	}
	if(co==7){
		var d= new Date();
		document.getElementById('m_end').value= getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		d.setDate(d.getDate() -7);
		document.getElementById('m_start').value=getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		
	}
	if(co==15){
		var d= new Date();
		document.getElementById('m_end').value= getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		d.setDate(d.getDate() -15);
		document.getElementById('m_start').value=getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		
	}
	if(co==30){
		var d= new Date();
	/*d.setDate(d.getDate() - 1);*/
		document.getElementById('m_end').value= getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		d.setMonth(d.getMonth() - 1);
		document.getElementById('m_start').value=getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		
	}
	if(co==-30){
		var d= new Date();
		document.getElementById('m_end').value= getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),d.getDate().toString());
		//d.setMonth(d.getMonth() - 1);
		document.getElementById('m_start').value=getFormattedDate(d.getFullYear(),(d.getMonth()+1).toString(),"01");
		
	}
}
function submit() {
	var ff = document.mform;
	ff.submit();
}

function goPage(link,on) {
		window.location.assign(link+"&page="+on)		
}

function enterTable(e,value){
    var key = window.event ? e.keyCode : e.which;
    if(key==13){
        if(value=="submit") submit();
        else{
    	document.getElementById(value).focus();
		document.getElementById(value).select();
		return false;
        } 
	}else
		return true;	
}

</script>

<div class="content_table">
				<table cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse;margin-left: -10px;margin-top: -20px;width: 980px;background: url('images/title_03.gif') repeat-x scroll 0% 0% transparent;" >
				<thead>
					<tr>
						<th style="text-align: left;background: url('images/title_03.gif') repeat-x scroll 0% 0% transparent;height: 24px;">
						<?php if($type==0) echo 'Danh sách khách hàng'; else if($type==1) echo 'Danh sách cửa hàng'; else echo 'Danh sách tài khoản';?>
						</th>
						
					</tr>
				</thead>
				</table>
				<br>
		 <div class="search_box">
			<form name="mform" method="GET" action="<?=base_url('account')?>">
				<div class="search_sbox">
					<ul>
						<li style="margin-top: 10px">Ngày tạo</li>
						
						<li><input name="m_start" id="m_start" type="text" value="<?=$m_start?>" readonly="readonly" style="width: 100px;">
						~<input name="m_end" id="m_end" type="text" value="<?=$m_end?>" readonly="readonly" style="width: 100px;"></li>
						
						<li class="divBtn" onclick="onchangetime(1)">Hôm nay</li>
						<li class="divBtn" onclick="onchangetime(-1)">Hôm qua</li>
						<li class="divBtn" onclick="onchangetime(-30)">Tháng này</li>
						<li class="divBtn" onclick="onchangetime(7)">Một tuần</li>
						<li class="divBtn" onclick="onchangetime(15)">Hai tuần</li>
						<li class="divBtn" onclick="onchangetime(30)">Một tháng</li>
					</ul>
					
					<ul>
						<li style="margin-top: 10px">Tên</li>
						<li><input style="width: 200px;" name="m_name" type="text" onkeypress="return enterTable(event,'m_name');" value="<?=$_REQUEST['m_name']?>"></li>
						<li><div class="divBtn" style="margin-right:15px" onclick="submit();">Tìm</div></li>
					</ul>
						
					
				</div>
			</form>
			</div>
			
		
			<table cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse;">
				<thead>
					<tr>
						<th style="width: 30px;">No.</th>
						<th style="width: 120px;">Họ tên</th>
						<th style="width: 120px;">Email</th>
						<th style="width: 100px;">Ngày gia nhập</th>
						<th style="width: 100px;">Trạng thái</th>
						<th style="width: 70px;">Phân loại</th>
						<th style="width: 70px;"></th>
					</tr>
				</thead>
				<tbody>
				<?php 
				$vitri=0;
				foreach ($list_account as $value ){
					$i++;
             		$vitri++;
					if($vitri>$pagestart && $vitri<=$pageend){
						
					?>
					<tr  style="cursor:pointer;">
						<td style="width: 30px;" ><?=$vitri?></td>
						<td><?=$value['name']?></td>
						<td><?=$value['email']?></td>
						<td><?=$value['join_day']?></td>
						<td><?php if($value['status']==1) echo "Đang sử dụng"; if($value['status']==0) echo "Bị khóa"; ?></td>
						<td><?php if($value['type']==1) echo "Cửa hàng"; if($value['type']==0) echo "Khách hàng"; ?></td>
						<td>
						<div class="divBtn" style="width:60px; float:right; margin:0px 5px;" onclick="location.href='<?=base_url('account/acc_detail?aid='.$value['id'])?>'">Cập nhật</div>
						</td>
					</tr>
				<?php 
				
					}
					
				}
				
				
				
				?>						
				</tbody>
			</table>

			<div style="text-align:center; margin:10px 0px;">
				<div class="paginate_simple">
				<?php $pages=ceil($page/10)-1;
						if($pages>0){
							?>
							<a href="javascript:goPage('<?=$link?>',<?=($pages-1)*10+1?>)"><?=$l_prev?></a>
							<?php 		
						}
				?>
				
					<?php
					$co=0;
					 for($i=1;$i<=$numpage;$i++){
						$co++;
						if($i>$pages*10 && $i<=($pages+1)*10){
						if($page==$i){
						?>
						<strong><?=$i?></strong>
						<?php }else{?>
						<a href="javascript:goPage('<?=$link?>',<?=$i?>)"><?=$i?></a>
						<?php }
						}
						?>
						
						
					<?php }
					if($page<=($pages+1)*10 && $co >($pages+1)*10){
						
							?>
							<a href="javascript:goPage('<?=$link?>',<?=($pages+1)*10+1?>)"><?=$l_next?></a>
							<?php 		
						}
					?>
				</div>
			</div>

			</div>